// C source file with the function definitions to handle BMD/BDL data

// check_j3dgraph_bmd_bdl() function
// function to check if a J3DGraph BMD/BDL is valid
j3dgraph_t check_j3dgraph_bmd_bdl(char * file)
{
  // check if it is BMD or BDL
  j3dgraph_t result = check_j3dgraph_bmd(file);
  return result == J3DGRAPH_NO_TYPE ? check_j3dgraph_bdl(file) : result;
}

// open_j3dgraph_bmd_bdl() function
// open a BMD/BDL (build a complete j3dgraph struct for BMD/BDL)
j3dgraph * open_j3dgraph_bmd_bdl(char * file_path)
{
  // check if the file is a BMD/BDL
  j3dgraph * file = open_j3dgraph_bmd(file_path);
  return file == NULL ? open_j3dgraph_bdl(file_path) : file;
}

// close_j3dgraph_bmd_bdl() function
// function to close a complete j3dgraph BMD/BDL structure (free it)
void close_j3dgraph_bmd_bdl(j3dgraph * file)
{
  // free the memory allocated by all functions
  if (file == NULL)
    return;
  
  // close the file depending on the type
  if ((file -> TYPE) == J3DGRAPH_BMD)
    close_j3dgraph_bmd(file);
  else if ((file -> TYPE) == J3DGRAPH_BDL)
    close_j3dgraph_bdl(file);
  // all done!
  return;
}

// print_j3dgraph_bmd_bdl() function
// print the information of a J3DGraph BMD/BDL
void print_j3dgraph_bmd_bdl(j3dgraph * file)
{
  // print everything header and sections
  // check ptr
  if (file == NULL)
    return;
  
  // print the file considering the type
  if (file -> TYPE == J3DGRAPH_BMD)
    print_j3dgraph_bmd(file);
  else if (file -> TYPE == J3DGRAPH_BDL)
    print_j3dgraph_bdl(file);
  // done!
  return;  
}
